import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jinke/utils/img_util.dart';
import 'package:jinke/utils/util.dart';

import '../../global/user/logic.dart';
import 'index.dart';
import 'widgets/cell.dart';
import 'widgets/widgets.dart';

class MePage extends GetView<MeController> {
  MePage({Key? key}) : super(key: key);
  final userCtrl = UserController();
  // 主视图
  Widget _buildView() {
    var user = userCtrl.state.user;
    return Stack(
      children: [
        Image.asset(
          'bg_wode.png'.imgPathMe,
          width: 1.sw,
          fit: BoxFit.cover,
        ),
        SafeArea(
            child: Align(
          alignment: Alignment.topCenter,
          child: Padding(
            padding: EdgeInsets.all(15.r),
            child: Text(
              '我的',
              style: TextStyle(
                  color: Colors.white,
                  fontSize: 17.r,
                  fontWeight: FontWeight.bold),
            ),
          ),
        )),
        Positioned(
          child: Container(
            margin: EdgeInsets.only(top: 190.r),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.vertical(
                top: Radius.circular(20.r),
              ),
            ),
          ),
        ),
        Container(
          child: ListView(
            children: [
              Container(
                // padding: EdgeInsets.symmetric(vertical: 20.r, horizontal: 30.r),
                margin: EdgeInsets.fromLTRB(20.r, 20.r, 20.r, 0),
                height: 170.r,
                alignment: Alignment.centerLeft,
                child: Row(
                  children: [
                    Container(
                      child: Obx(
                        () => loadAvater(
                            size: 62,
                            url: userCtrl.state.userObs.value.headUrl),
                      ),
                      decoration: BoxDecoration(
                          border: Border.all(color: Colors.white, width: 0),
                          borderRadius: BorderRadius.all(Radius.circular(180))),
                      width: 62,
                      height: 62,
                    ),
                    SizedBox(
                      width: 10.r,
                    ),
                    Column(
                      children: [
                        Text(
                          user?.userName ?? '',
                          style: TextStyle(
                              color: ColorsUtil.white,
                              fontSize: 20.r,
                              fontWeight: FontWeight.bold),
                        ),
                        Text(
                          user?.loginPostInfo?.postName ?? '',
                          style: TextStyle(
                            color: ColorsUtil.white,
                            fontSize: 12.r,
                          ),
                        )
                      ],
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisAlignment: MainAxisAlignment.center,
                    ),
                  ],
                ),
              ),

              Column(
                children: controller.state.list
                    .asMap()
                    .map(
                      (key, value) => MapEntry(
                        key,
                        MeCell(
                          icon: value.icon!,
                          title: value.name,
                          content: value.content,
                          onTap: value.onTap,
                        ),
                      ),
                    )
                    .values
                    .toList(),
              ),
              GestureDetector(
                onTap: () {
                  controller.actionLoginOut();
                },
                child: Container(
                  height: 44.r,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    color: Color(0xfff8f8f8),
                    borderRadius: BorderRadius.circular(22.r),
                  ),
                  margin: EdgeInsets.only(top: 50.r, left: 80.r, right: 80.r),
                  child: Text(
                    '退出',
                    style:
                        pfSCStyle(color: ColorsUtil.content, fontSize: 15.sp),
                  ),
                ),
              ),
              // controller.state.img == null
              //     ? SizedBox()
              //     : Image.memory(controller.state.img),
            ],
          ),
        ),
        SafeArea(
            child: Align(
          alignment: Alignment.topLeft,
          child: BackButton(
            color: Colors.white,
          ),
        )),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MeController>(
      builder: (_) {
        return Scaffold(
          // appBar: AppBar(title: const Text("me"),centerTitle: true,backgroundColor: Colors.transparent,elevation: 0,),
          body: _buildView(),
        );
      },
    );
  }
}
